﻿package mortal.game.view.common.tooltip.tooltips
{
    import Message.Client.*;
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.text.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.tooltip.tooltips.base.*;
    import mortal.game.view.palyer.data.*;
    import mortal.game.view.palyer.util.*;
    import mortal.game.view.skill.*;

    public class ToolTipSkill extends ToolTipScaleBg
    {
        private var _skill:TSkill;
        private var _txtDesc:GTextFiled;
        private var _txtType:GTextFiled;
        private var _txtName:GTextFiled;
        private var _line:ScaleBitmap;
        private var _txtUnlock:GTextFiled;
        private var _cur:AutoLayoutTextContainer;
        private var _line1:ScaleBitmap;

        public function ToolTipSkill()
        {
            this.initUI();
            return;
        }// end function

        override public function get width() : Number
        {
            return _scaleBg.width;
        }// end function

        override public function get height() : Number
        {
            return _scaleBg.height;
        }// end function

        private function initUI() : void
        {
            setBg(ImagesConst.ToolTipBg);
            this.paddingLeft = 8;
            this.paddingTop = 8;
            this.paddingBottom = 8;
            this.paddingRight = 8;
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.size = 14;
            _loc_1.color = 16777215;
            _loc_1.bold = true;
            this._txtType = UIFactory.gTextField("", 0, 0, 120, 22, contentContainer2D, _loc_1);
            _loc_1 = GlobalStyle.textFormatPutong;
            _loc_1.size = 14;
            _loc_1.color = 65280;
            _loc_1.bold = true;
            this._txtName = UIFactory.gTextField("", 85, 0, 120, 22, contentContainer2D, _loc_1);
            this._txtDesc = UIFactory.gTextField("", 0, 30, 222, 100, contentContainer2D);
            this._txtDesc.multiline = true;
            this._txtDesc.wordWrap = true;
            _loc_1 = GlobalStyle.textFormatHong;
            _loc_1.size = 13;
            _loc_1.align = TextFormatAlign.CENTER;
            this._txtUnlock = UIFactory.gTextField("", -5, 30, 232, 24, contentContainer2D, _loc_1);
            this._line = UIFactory.bg(0, 30, 232, 2, contentContainer2D, ImagesConst.SplitLine);
            this._line1 = UIFactory.bg(0, 30, 232, 2, contentContainer2D, ImagesConst.SplitLine);
            this._cur = new AutoLayoutTextContainer();
            this._cur.y = 137;
            this._cur.addNewText(120, "", 12, GlobalStyle.colorAnjinUint);
            this._cur.addNewText(120, "", 12, GlobalStyle.colorLanUint);
            this._cur.addNewText(120, "", 12, GlobalStyle.colorLanUint);
            this._cur.addNewText(120, "", 12, GlobalStyle.colorLanUint);
            this._cur.addNewText(120, "", 12, GlobalStyle.colorLanUint);
            this._cur.addNewText(120, "", 12, GlobalStyle.colorLanUint);
            this._cur.verticalGap = -6;
            contentContainer2D.addChild(this._cur);
            return;
        }// end function

        override public function set data(param1) : void
        {
            super.data = param1;
            this._skill = (param1 as SkillInfo).tSkill;
            this._txtType.text = "[" + SkillUtil.getSkillUseTypeName(this._skill) + "]";
            var _loc_2:* = SkillUtil.isOtherSkill(this._skill);
            if (_loc_2)
            {
                this._txtName.htmlText = HTMLUtil.addColor(this._skill.name, ColorConfig.instance.getItemColorString(this._skill.skillLevel));
            }
            else
            {
                DisplayUtil.removeMe(this._line);
                DisplayUtil.removeMe(this._txtUnlock);
                this._txtName.text = this._skill.name;
            }
            if (SkillUtil.alySkillDesc(this._skill))
            {
                this._txtDesc.htmlText = SkillUtil.alySkillDesc(this._skill);
            }
            this._txtDesc.height = this._txtDesc.textHeight + 8;
            var _loc_3:* = this._txtDesc.y + this._txtDesc.textHeight + 8;
            if (_loc_2)
            {
                _loc_3 = this.setUnlockInfos(_loc_3);
            }
            this._cur.setText(0, Language.getStringByParam(20236, this._skill.skillLevel));
            this._cur.setText(1, Language.getStringByParam(20237, this._skill.consume));
            this._cur.setText(2, Language.getStringByParam(20238, SkillUtil.getCoolDownTimeStr(this._skill, true)));
            this._cur.setText(3, Language.getStringByParam(20239, this._skill.distance));
            this._cur.setText(4, Language.getStringByParam(20240, SkillUtil.getBassicAttackPercentage(this._skill)));
            this._cur.setText(5, Language.getStringByParam(20241, SkillUtil.getAttachAttackValue(this._skill)));
            this._line1.y = _loc_3;
            this._cur.y = this._line1.y + 10;
            _scaleBg.setSize(235, this._cur.y + this._cur.height + paddingBottom + paddingTop - 3);
            return;
        }// end function

        private function setUnlockInfos(param1:int) : int
        {
            var _loc_2:* = GameDefConfig.instance.getOtherSkillTypeByPosType(this._skill.posType);
            var _loc_3:* = getIsFashionUnlocked(_loc_2, this._skill.posType);
            if (_loc_3 == -1)
            {
                DisplayUtil.removeMe(this._line);
                DisplayUtil.removeMe(this._txtUnlock);
                return param1;
            }
            contentContainer2D.addChild(this._line);
            contentContainer2D.addChild(this._txtUnlock);
            this._line.y = param1;
            param1 = param1 + 5;
            this._txtUnlock.y = param1;
            param1 = param1 + 26;
            var _loc_4:* = getOtherSkillPartName(_loc_2);
            this._txtUnlock.htmlText = Language.getStringByParam(20845, _loc_4, _loc_3);
            return param1;
        }// end function

        public static function getOtherSkillPartName(param1:int) : String
        {
            var _loc_2:String = "";
            switch(param1)
            {
                case ESkillCategory._EMountSkill:
                {
                    _loc_2 = Language.getString(20846);
                    break;
                }
                case ESkillCategory._EPetSkill:
                {
                    _loc_2 = Language.getString(20847);
                    break;
                }
                case ESkillCategory._EArtifactSkill:
                {
                    _loc_2 = Language.getString(20848);
                    break;
                }
                case ESkillCategory._EClothesSkill:
                {
                    _loc_2 = Language.getString(20849);
                    break;
                }
                case ESkillCategory._EDragonSoulSkill:
                {
                    _loc_2 = Language.getString(20850);
                    break;
                }
                case ESkillCategory._EFightMethodSkill:
                {
                    _loc_2 = Language.getString(20851);
                    break;
                }
                case ESkillCategory._EFightSoulSkill:
                {
                    _loc_2 = Language.getString(20852);
                    break;
                }
                case ESkillCategory._EWingSkill:
                {
                    _loc_2 = Language.getString(20853);
                    break;
                }
                case ESkillCategory._EHolyBookSkill:
                {
                    _loc_2 = Language.getString(20854);
                    break;
                }
                case ESkillCategory._EWarShieldSkill:
                {
                    _loc_2 = Language.getString(20855);
                    break;
                }
                case ESkillCategory._EMonsterSoulSkill:
                {
                    _loc_2 = Language.getString(20856);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

        public static function getIsFashionUnlocked(param1:int, param2:int) : int
        {
            var _loc_3:TSkill = null;
            var _loc_7:String = null;
            var _loc_8:int = 0;
            var _loc_9:Array = null;
            var _loc_10:TMountConfig = null;
            var _loc_11:Dictionary = null;
            var _loc_12:int = 0;
            var _loc_13:int = 0;
            if (param1 == ESkillCategory._EPetSkill)
            {
                if (Cache.instance.newPet.pet == null)
                {
                    return -1;
                }
                _loc_8 = Cache.instance.newPet.pet.code;
                _loc_9 = MountConfig.instance.getFashionsByType(EAdvanceComponentType._EAdvanceComponentTypePet);
                for each (_loc_10 in _loc_9)
                {
                    
                    if (!_loc_10.skillList)
                    {
                        continue;
                    }
                    _loc_3 = SkillConfig.instance.getInfoById(int(_loc_10.skillList));
                    if (_loc_3.posType == param2)
                    {
                        if (_loc_8 >= _loc_10.code)
                        {
                            return -1;
                        }
                        return _loc_10.code;
                    }
                }
                return -1;
            }
            else if (param1 == ESkillCategory._EMountSkill)
            {
                if (Cache.instance.mount.mountData == null)
                {
                    return -1;
                }
                _loc_11 = MountConfig.instance.mountMap;
                _loc_12 = Cache.instance.mount.mountData.mountLevel;
                for each (_loc_10 in _loc_11)
                {
                    
                    if (!_loc_10.skillList)
                    {
                        continue;
                    }
                    _loc_3 = SkillConfig.instance.getInfoById(int(_loc_10.skillList));
                    if (_loc_3.posType == param2)
                    {
                        if (_loc_12 >= _loc_10.code)
                        {
                            return -1;
                        }
                        return _loc_10.code;
                    }
                }
                return -1;
            }
            var _loc_4:* = getFashionTypeBySkillType(param1);
            var _loc_5:* = FashionUtil.getAllCodeDefaultSkills(_loc_4);
            var _loc_6:* = Cache.instance.fashion.getFashionInfo(_loc_4);
            if (_loc_6 == null || _loc_5 == null)
            {
                return -1;
            }
            for each (_loc_7 in _loc_5.keys)
            {
                
                _loc_13 = int(_loc_7);
                _loc_3 = SkillConfig.instance.getInfoById(_loc_5.getValue(_loc_13) as int);
                if (_loc_3.posType == param2)
                {
                    return _loc_13 <= _loc_6.advanceInfo.code ? (-1) : (_loc_13);
                }
            }
            return -1;
        }// end function

        private static function getFashionTypeBySkillType(param1:int) : int
        {
            switch(param1)
            {
                case ESkillCategory._EArtifactSkill:
                {
                    return EFashionType._EFashionWeapon;
                }
                case ESkillCategory._EClothesSkill:
                {
                    return EFashionType._EFashionClothes;
                }
                case ESkillCategory._EDragonSoulSkill:
                {
                    return EFashionType._EFashionDragonSoul;
                }
                case ESkillCategory._EFightMethodSkill:
                {
                    return EFashionType._EFashionFightMethod;
                }
                case ESkillCategory._EFightSoulSkill:
                {
                    return EFashionType._EFashionFightSoul;
                }
                case ESkillCategory._EWingSkill:
                {
                    return EFashionType._EFashionWing;
                }
                case ESkillCategory._EHolyBookSkill:
                {
                    return EAdvanceComponentType._EAdvanceComponentTypeHolyBook;
                }
                case ESkillCategory._EWarShieldSkill:
                {
                    return EAdvanceComponentType._EAdvanceComponentTypeWarShield;
                }
                case ESkillCategory._EMonsterSoulSkill:
                {
                    return EAdvanceComponentType._EAdvanceComponentTypeMonsterSoul;
                }
                default:
                {
                    break;
                }
            }
            return ESkillCategory._EArtifactSkill;
        }// end function

    }
}
